package com.besttone.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;


public class ConsumerService {
	public final static Logger logger = LoggerFactory.getLogger(ConsumerService.class);

	@KafkaListener(id="myMessageListener1",topics= {"test1"})
    public void consumer1(ConsumerRecord<String, String> data) {
        String topic = data.topic();//消费的topic
        logger.info("-------------recieve message from {} topic-------------", topic);
        logger.info("partition:{}", String.valueOf(data.partition()));//消费的topic的分区
        logger.info("offset:{}", String.valueOf(data.offset()));//消费者的位置
        logger.info("get message from {} topic : {}", topic, data.value());//接收到的消息
    }
	
	@KafkaListener(id = "myMessageListener2", topics = { "test2"})
    public void consumer2(ConsumerRecord<String, String> data) {
        String topic = data.topic();//消费的topic
        logger.info("-------------recieve message from {} topic-------------", topic);
        logger.info("partition:{}", String.valueOf(data.partition()));//消费的topic的分区
        logger.info("offset:{}", String.valueOf(data.offset()));//消费者的位置
        logger.info("get message from {} topic : {}", topic, data.value());//接收到的消息
    }
}
